import { LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE } from 'actions';

const login = (state = { loading: false, data: null, error: null }, action) => {
  switch (action.type) {
    case LOGIN_REQUEST:
      return Object.assign({}, state, { loading: true });
    case LOGIN_SUCCESS:
      return Object.assign({}, state, { loading: false, data: action.data, error: null });
    case LOGIN_FAILURE:
      return Object.assign({}, state, { loading: false, data: null, error: action.error });
    default:
      return state;
  }
};

export default login;
